package com.ww.learn.lambdas

// 代码无法编译通过，因为它将一个默认Int值7赋给lambda
// The integer literal does not conform to the expected type (Int) -> Int
//fun myFun1(x: Int = 6, y: (Int) -> Int = 7): Int {
//    return y(x)
//}

//Type mismatch.
//Required: Unit
//Found: Int
//fun myFun2(x: Int = 6, y: (Int) -> Int = { it }) {
//    return y(x)
//}

fun myFun3(x: Int = 6, y: (Int) -> Int = { x: Int -> x + 6 }): Int {
    return y(x)
}

// z被赋值一个有效的lambda作为其默认值
fun myFun4(
    x: Int, y: Int, z: (Int, Int) -> Int = { x: Int, y: Int ->
        x + y
    }
) {
    z(x, y)
}

fun myFun5(
    x: (Int) -> Int = {
        println(it)
        it + 7
    }
) {
    x(4)
}